package com.lovegu.book.concurrence;

import lombok.SneakyThrows;

/**
 * @author 老顾
 * @title: ReadStackLog
 * @projectName java-restudy
 * @email: 1437594522@qq.com
 * @date 2022/11/5 9:02
 */
public class ReadStackLog {
    public static void main(String[] args) {
        new Thread(new TimeWaiting(),"TimeWaitingThread").start();
        new Thread(new Waiting(),"WaitingThread").start();
        new Thread(new Blocked(),"TlockedThread-1").start();
        new Thread(new Blocked(),"TlockedThread-2").start();
    }
}
class TimeWaiting implements Runnable {

    //线程不断睡眠
    @SneakyThrows
    @Override
    public void run() {
        while (true) {
            Thread.sleep(10000000);
        }
    }
}
class Waiting implements Runnable {

    @Override
    public void run(){
        while (true) {
            synchronized (Waiting.class){
                try {
                    Waiting.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
class Blocked implements Runnable {

    @SneakyThrows
    @Override
    public void run() {
        synchronized (Blocked.class) {
            while (true) {
                Thread.sleep(10000000);
            }
        }
    }
}